﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Area.SystemManager;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.PoModel.SystemSettings.InstituTions;
using SystemCenterSoa.Service.SystemSettings.InstituTions;

namespace SystemCenterSoa.ApiProject.Area.SystemSettings.InstituTions
{
    [AllowAnonymous]
    public class InterviewController : SystemManagerBaseController
    {
        private InterviewService _interviewService;
        public InterviewController(InterviewService interviewServicepublic)
        {
            _interviewService = interviewServicepublic;
        }
        [HttpGet]
        public ResultModel<List<DepartmentOfManagementPo>> BindDep()
        {
            try
            {
                var data = _interviewService.BindDep();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DepartmentOfManagementPo>>(ex);
            }
        }
        [HttpPost]
        public ResultModel<PagerResult<InterviewManagementPo>> SearchPage(SearchModel sm)
        {
            try
            {
                var data = _interviewService.SearchPage(sm);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<InterviewManagementPo>>(ex);
            }


        }
        [HttpPost]
        public ResultModel<bool> InterMentAdd(InterviewManagementPo view)
        {
            try
            {
                var data = _interviewService.InterMentAdd(view);
                if (data == false) //返回添加id为0,  说明添加没有成功, 直接返回失败
                {
                    return MyFail<bool>("添加没有成功!");
                }
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        [HttpGet]
        public ResultModel<InterviewManagementPo> GetInterMentById(int id)
        {
            try
            {
                var data = _interviewService.GetInterMentById(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<InterviewManagementPo>(ex);
            }
        }
        [HttpPost]
        public ResultModel<bool> InterMentUpdate(InterviewManagementPo view)
        {
            try
            {
                var data = _interviewService.InterMentUpdate(view);
                if (data) //如果是成功就更新成功
                {
                    return MyOk(data);

                }
                return MyFail<bool>("更新没有成功!");

            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        
        [HttpPost]
        public ResultModel<bool> InterMentDelete(int id)
        {
            try
            {
                var data = _interviewService.InterMentDelete(id);
                if (data) //如果是成功就更新成功
                {
                    return MyOk(data);

                }
                return MyFail<bool>("删除没有成功!");

            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
    }
}
